package com.strawberry.chat2;

import android.app.Application;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.oblador.vectoricons.VectorIconsPackage;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.strawberry.chat2.library.common.CommonPackage;
import com.strawberry.chat2.library.netease.*;
import com.strawberry.chat2.library.netease.p2p.Util;
import com.strawberry.chat2.library.splash.SplashScreenReactPackage;
import com.strawberry.chat2.library.gesturehandler.react.RNGestureHandlerPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import com.strawberry.chat2.library.wechat.WeChatPackage;
import com.strawberry.chat2.views.svgaImage.SvgaImagePackage;
import com.strawberry.chat2.views.webpImage.WebpImagePackage;
import com.strawberry.chat2.views.neteasePlayer.neteasePlayerPackage;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.PushAgent;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

        @Override
        public boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
                    new CommonPackage(),
                    new WeChatPackage(),
                    new VectorIconsPackage(),
                    new SplashScreenReactPackage(),
                    new RNGestureHandlerPackage(),
                    new RNFetchBlobPackage(),
                    new NeteasePackage(),
                    new neteasePlayerPackage(),
                    new WebpImagePackage(),
                    new SvgaImagePackage()
            );
        }

        @Override
        protected String getJSMainModuleName() {
            return "index";
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        SoLoader.init(this, /* native exopackage */ false);
        //云信初始化
        Util.init(this);
        //友盟初始化
        UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, "4af62ea7c995a1390906fec2f40825e0");
        //获取消息推送代理示例
        PushAgent mPushAgent = PushAgent.getInstance(this);
        //注册推送服务，每次调用register方法都会回调该接口
        mPushAgent.register(new IUmengRegisterCallback() {
            @Override
            public void onSuccess(String deviceToken) {
                //注册成功会返回deviceToken deviceToken是推送消息的唯一标志
                Log.i("fanghailiang", "注册成功：deviceToken：-------->  " + deviceToken);
            }

            @Override
            public void onFailure(String s, String s1) {
                Log.e("fanghailiang", "注册失败：-------->  " + "s:" + s + ",s1:" + s1);
            }
        });
    }

}
